<template>
  <el-container>
    <el-main>
      <el-form ref="loginForm" :model="loginForm" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin">登录</el-button>
        </el-form-item>
      </el-form>
    </el-main>
  </el-container>
</template>
  
  <script>
export default {
  data() {
    return {
      loginForm: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    handleLogin() {
      // 模拟登录成功
      if (
        this.loginForm.username === "admin" &&
        this.loginForm.password === "123456"
      ) {
        this.$message.success("登录成功");
        // 更新用户信息
        this.$store.commit("updateUser", {
          username: "admin",
          avatar:
            "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
        });
        // 跳转到用户页面
        this.$router.push("/user");
      } else {
        this.$message.error("用户名或密码错误");
      }
    },
  },
};
</script>
  
  <style scoped>
.el-main {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
</style>
  